﻿@model OT.Areas.Student.Models.ChangePassword
@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Student/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <div class="form-horizontal">
        <div id="divMsgIndex"></div>
    </div>
    <div class="admin-form" style="margin-top: 0px;">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="widget wred">
                        <div class="widget-head">
                            <i class="fa fa-lock"></i>Change PassWord 
                        </div>
                        <div class="widget-content">
                            <div class="padd">
                                <div class="form-horizontal">
                                    <div class="form-group" id="divPassword">
                                        <label class="control-label col-lg-4" for="inputEmail">old Password</label>
                                        <div class="col-lg-7 ">
                                            <input class="form-control" placeholder="Enter Current Password" type="password" id="Password">
                                        </div>
                                    </div>
                                    <div class="form-group" id="divNewPassword">
                                        <label class="control-label col-lg-4" for="inputPassword">New Password</label>
                                        <div class="col-lg-7 ">
                                            <input class="form-control" placeholder="Enter New Password" type="password" id="NewPassword">
                                        </div>
                                    </div>
                                    <div class="form-group" id="divConfPassword">
                                        <label class="control-label col-lg-4" for="inputEmail">Re-Enter Password</label>
                                        <div class="col-lg-7 control-label">
                                            <input class="form-control" placeholder="Re-Enter New Password" type="password" id="ConfirmPassword">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="widget-foot">
                            <div class="pull-right">
                                <button class="btn btn-default" type="submit" value="Save" id="btnChange"><i class="icon-cog"></i>Save</button>
                                <button type="reset" class="btn btn-default btn-sm">Reset</button>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#h2Title').html("<i class='fa fa-key'></i> Change PassWord ");
            $('#aTitle').html('Change Password');
            $('#liDashboard').addClass("open");
            $("#Password").focusout(function () {
                $.getJSON("/Student/ChangePassword/PasswordCheck", { Password: btoa($(this).val()) },
                      function (classesData) {
                          if (classesData == 0) {
                              showMsg('divMsgIndex', 'Old password is wrong!', 'warning');
                          }
                          else { }
                      });
            });

            $("#btnChange").click(function (e) {
                e.preventDefault();
                var pass =btoa($("#Password").val());
                var conpass = btoa($("#ConfirmPassword").val());
                var newpass = btoa($("#NewPassword").val());
                if (pass == '' || conpass == '' || newpass == '') {
                    showMsg('divMsgIndex', 'Must Be Enter Value in All Field!', 'danger');
                    (pass == '') ? $('#divPassword').addClass('has-error') : $('#divPassword').removeClass('has-error');
                    (conpass == '') ? $('#divConfPassword').addClass('has-error') : $('#divConfPassword').removeClass('has-error');
                    (newpass == '') ? $('#divNewPassword').addClass('has-error') : $('#divNewPassword').removeClass('has-error');
                }
                else if (conpass != newpass) {
                    showMsg('divMsgIndex', 'Confirm Password Not Matched!', 'danger');
                }
                else {
                    $.ajax({
                        url: "/Student/ChangePassword/Index?Password=" + pass + "&NewPassword=" + newpass,
                        type: "POST",
                        success: function (result) {
                            if (result != "") {
                                showMsg('divMsgIndex', 'Password Successfuly Changed!', 'success');
                            }
                            else {
                                showMsg('divMsgIndex', 'Password not Changed!!Error', 'danger');
                            }
                        },
                        error: function (data) {
                        }
                    });
                }
            });

            $("#btnOk").click(function (e) {
                e.preventDefault();
                window.location = "/Student";
            });
        });
    </script>
}